package com.cls.business.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cls.business.entity.ClassDistributionRecord;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 课题评审记录表 Mapper
 *
 * @author slx
 * @date 2021-03-02 15:54:14
 */
@Repository
public interface ClassDistributionRecordMapper extends BaseMapper<ClassDistributionRecord> {


    @Select("SELECT\n" +
            "\tdistribution_record_id,\n" +
            "\trecord.expert_id,\n" +
            "\trecord.plan_id ,review_finished,\n" +
            "\tmobile,\n" +
            "\t`name`,\n" +
            "\treview_finished_date,\n" +
            "\treview_text,\n" +
            "\trecord.file_id \n" +
            "FROM\n" +
            "\tbiz_class_distribution_record record\n" +
            "\tLEFT JOIN biz_expert expert ON expert.expert_id = record.expert_id \n" +
            "WHERE\n" +
            "\trecord.plan_id = #{planId} and record.is_delete=0  and expert.is_delete=0  ORDER BY review_finished DESC ,review_finished_date DESC")
    List<ClassDistributionRecord> findRecordsByPlanId(@Param("planId") Long planId);

    @Select("SELECT expert_id FROM biz_class_distribution_record rc WHERE rc.is_delete=0 AND rc.plan_id = #{planId}")
    List<Long> findExpertIdsByExcludPlanId(@Param("planId") Long planId);


    @Select("SELECT rc.*,tp.`year` FROM biz_class_distribution_record rc LEFT JOIN biz_topic_plan tp ON tp.plan_id=rc.plan_id WHERE rc.is_delete=0 AND tp.is_delete=0 AND rc.expert_id=#{expertId}\n" +
            "ORDER BY review_finished,review_finished_date ")
    List<ClassDistributionRecord> findRecordsAndYearByExpertId(@Param("expertId") Long expertId);
}
